package com.wee.aircoach_user;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.android.volley.toolbox.ImageLoader;
import com.bigtotoro.widgets.AppProgressBar;

import java.io.File;

/**
 * Created by Solomon on 2015/11/23.
 */
public class SettingActivity extends Activity implements View.OnClickListener{
    private ImageView user_po;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        intView();
        initphoto();
    }

    private void initphoto() {
        try{
          user_po = (ImageView) findViewById(R.id.user_po);
        String path=getIntent().getStringExtra("path");
         if(path!=null){
             ImageLoader.ImageListener imageListener = ImageLoader.getImageListener(user_po, R.drawable.coach_no, R.drawable.coach_no);
             MyApplication.getInstance().getImageLoader().get(path, imageListener, 100, 100);
            }

        }catch(Exception r){}

    }
    private void intView() {
        findViewById(R.id.back).setOnClickListener(this);
        findViewById(R.id.set_item0).setOnClickListener(this);
        findViewById(R.id.set_item1).setOnClickListener(this);
        findViewById(R.id.set_item2).setOnClickListener(this);
        findViewById(R.id.set_item3).setOnClickListener(this);
        findViewById(R.id.set_item4).setOnClickListener(this);
        findViewById(R.id.set_item5).setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.back:
              finish();
                break;
            case R.id.set_item0:
                startActivity(new Intent(this, ProfileInfoActivity.class));
            break;
            case R.id.set_item1:
                startActivity(new Intent(this, ProfilePurposeActivity.class));
                break;
            case R.id.set_item2:
          //缓存
                String sdPath = Environment
                        .getExternalStorageDirectory().getAbsolutePath()
                        + "/VideoAirCache/";
                File f = new File(sdPath);
                AppProgressBar.checkAndCreateProgressBar(this);
                deleteAllFiles(f);
                AppProgressBar.closeProgressBar();
                Toast.makeText(this, "清理完成", Toast.LENGTH_SHORT).show();
          //      Toast.makeText(this, "暂未处理", Toast.LENGTH_SHORT).show();
               break;
            case R.id.set_item3:
                startActivity(new Intent(this, AboutActivity.class));
                break;
            case R.id.set_item4:
            //评分
              Toast.makeText(this, "暂未处理", Toast.LENGTH_SHORT).show();
                break;
            case R.id.set_item5:
           //退出登录
                Toast.makeText(this, "暂未处理", Toast.LENGTH_SHORT).show();
                break;
        }
    }

    private void deleteAllFiles(File root) {
        File files[] = root.listFiles();
        if (files != null)
            for (File f : files) {
                if (f.isDirectory()) { // 判断是否为文件夹
                    deleteAllFiles(f);
                    try {
                        f.delete();
                    } catch (Exception e) {
                    }
                } else {
                    if (f.exists()) { // 判断是否存在
                        deleteAllFiles(f);
                        try {
                            f.delete();
                        } catch (Exception e) {
                        }
                    }
                }
            }

    }

}
